home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_08 / 1108069a < prev    next >
Text File  |  1993-06-06  |  5KB  |  186 lines

  1.      /*******************************************
  2.      *
  3.      *   opening(...
  4.      *
  5.      *   Opening is erosion followed by dilation.
  6.      *   This routine will use the mask erosion
  7.      *   and dilation.  You could use the other
  8.      *   types and you could mix the two types.
  9.      *
  10.      *   The number parameter specifies how
  11.      *   erosions to perform before doing one
  12.      *   dilation.
  13.      *
  14.      *******************************************/
  15.  
  16. opening(in_name, out_name, the_image, out_image,
  17.         il, ie, ll, le, value, mask_type, number)
  18.    char   in_name[], out_name[];
  19.    int    il, ie, ll, le, number;
  20.    short  the_image[ROWS][COLS],
  21.           out_image[ROWS][COLS],
  22.           mask_type, value;
  23. {
  24.    int    a, b, count, i, j, k;
  25.    int    length, width;
  26.    struct tiff_header_struct image_header;
  27.    short  mask[3][3], max;
  28.  
  29.       /**************************************
  30.       *
  31.       *   Copy the 3x3 erosion-dilation mask
  32.       *   specified by the mask_type.
  33.       *
  34.       ***************************************/
  35.  
  36.    switch(mask_type){
  37.       case 1:
  38.          copy_3_x_3(mask, edmask1);
  39.          break;
  40.       case 2:
  41.          copy_3_x_3(mask, edmask2);
  42.          break;
  43.       case 3:
  44.          copy_3_x_3(mask, edmask3);
  45.          break;
  46.       case 4:
  47.          copy_3_x_3(mask, edmask4);
  48.          break;
  49.       default:
  50.          printf("\nInvalid mask type, using mask 4");
  51.          copy_3_x_3(mask, edmask4);
  52.          break;
  53.    }
  54.  
  55.    if(does_not_exist(out_name)){
  56.       printf("\n\n output file does not exist %s", out_name);
  57.       read_tiff_header(in_name, &image_header);
  58.       round_off_image_size(&image_header,
  59.                            &length, &width);
  60.       image_header.image_length = length*ROWS;
  61.       image_header.image_width  = width*COLS;
  62.       create_allocate_tiff_file(out_name, &image_header,
  63.                                 out_image);
  64.    }  /* ends if does_not_exist */
  65.  
  66.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  67.  
  68.    mask_erosion(in_name, out_name, the_image,
  69.                 out_image, il, ie, ll, le,
  70.                 value, mask_type);
  71.  
  72.    if(number > 1){
  73.       count = 1;
  74.       while(count < number){
  75.          count++;
  76.          mask_erosion(out_name, out_name, the_image,
  77.                        out_image, il, ie, ll, le,
  78.                        value, mask_type);
  79.       }  /* ends while */
  80.    }  /* ends if number > 1 */
  81.  
  82.    mask_dilation(out_name, out_name, the_image,
  83.                  out_image, il, ie, ll, le,
  84.                  value, mask_type);
  85.  
  86.    write_array_into_tiff_image(out_name, out_image,
  87.                                il, ie, ll, le);
  88.  
  89. }  /* ends opening */
  90.  
  91.  
  92.  
  93.  
  94.  
  95.      /*******************************************
  96.      *
  97.      *   closing(...
  98.      *
  99.      *   Closing is dilation followed by erosion.
  100.      *   This routine will use the mask erosion
  101.      *   and dilation.  You could use the other
  102.      *   types and you could mix the two types.
  103.      *
  104.      *   The number parameter specifies how
  105.      *   dilations to perform before doing one
  106.      *   erosion.
  107.      *
  108.      *******************************************/
  109.  
  110. closing(in_name, out_name, the_image, out_image,
  111.         il, ie, ll, le, value, mask_type, number)
  112.    char   in_name[], out_name[];
  113.    int    il, ie, ll, le, number;
  114.    short  the_image[ROWS][COLS],
  115.           out_image[ROWS][COLS],
  116.           mask_type, value;
  117. {
  118.    int    a, b, count, i, j, k;
  119.    int    length, width;
  120.    struct tiff_header_struct image_header;
  121.    short  mask[3][3], max;
  122.  
  123.       /**************************************
  124.       *
  125.       *   Copy the 3x3 erosion-dilation mask
  126.       *   specified by the mask_type.
  127.       *
  128.       ***************************************/
  129.  
  130.    switch(mask_type){
  131.       case 1:
  132.          copy_3_x_3(mask, edmask1);
  133.          break;
  134.       case 2:
  135.          copy_3_x_3(mask, edmask2);
  136.          break;
  137.       case 3:
  138.          copy_3_x_3(mask, edmask3);
  139.          break;
  140.       case 4:
  141.          copy_3_x_3(mask, edmask4);
  142.          break;
  143.       default:
  144.          printf("\nInvalid mask type, using mask 4");
  145.          copy_3_x_3(mask, edmask4);
  146.          break;
  147.    }
  148.  
  149.    if(does_not_exist(out_name)){
  150.       printf("\n\n output file does not exist %s", out_name);
  151.       read_tiff_header(in_name, &image_header);
  152.       round_off_image_size(&image_header,
  153.                            &length, &width);
  154.       image_header.image_length = length*ROWS;
  155.       image_header.image_width  = width*COLS;
  156.       create_allocate_tiff_file(out_name, &image_header,
  157.                                 out_image);
  158.    }  /* ends if does_not_exist */
  159.  
  160.    read_tiff_image(in_name, the_image, il, ie, ll, le);
  161.  
  162.    mask_dilation(in_name, out_name, the_image,
  163.                  out_image, il, ie, ll, le,
  164.                  value, mask_type);
  165.  
  166.    if(number > 1){
  167.       count = 1;
  168.       while(count < number){
  169.          count++;
  170.          mask_dilation(out_name, out_name, the_image,
  171.                         out_image, il, ie, ll, le,
  172.                         value, mask_type);
  173.       }  /* ends while */
  174.    }  /* ends if number > 1 */
  175.  
  176.    mask_erosion(out_name, out_name, the_image,
  177.                 out_image, il, ie, ll, le,
  178.                 value, mask_type);
  179.  
  180.    write_array_into_tiff_image(out_name, out_image,
  181.                                il, ie, ll, le);
  182.  
  183. }  /* ends closing */
  184.  
  185.  
  186.